﻿@{
    Layout = null;
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>供货商分店关系管理</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" type="text/css" href="/Styles/demo.css" />
    <script src="/scripts/boot.js" type="text/javascript"></script>
</head>
<body>
    <div class="mini-fit">
        <div class="mini-splitter" style="width: 100%; height: 100%;">
            <div size="340" showcollapsebutton="true">
                <div class="mini-toolbar" style="padding: 2px; border-top: 0; border-left: 0; border-right: 0;">
                    <input class="mini-textbox" id="treekey" style="width: 150px;" />
                    <a class="mini-button" iconcls="icon-search" plain="true" onclick="treesearch">查找</a>
                </div>
                <div class="mini-fit">
                    <ul id="tree1" class="mini-tree" url="/Archives/SearchAllSuppliers" style="width: 100%;"
                        showtreeicon="true" textfield="SupName" idfield="Id" parentfield="pid" resultastree="false">
                    </ul>
                </div>
            </div>
            <div showcollapsebutton="true">
                <div class="mini-toolbar" style="border-bottom: 0; padding: 0px;">
                    <table style="width: 100%;">
                        <tr>
                            <td style="width: 100%;">
                                <a class="mini-button" iconcls="icon-save" onclick="saveData()" plain="true">保存</a>
                                <a class="mini-button" iconCls="icon-ok" onclick="selectAll()" plain="true">反选</a>
                            </td>
                            <td style="white-space: nowrap;">
                            </td>
                        </tr>
                    </table>
                </div>
                <div id="datagrid1" allowcelledit="true" class="mini-datagrid" url="/Archives/SearchGoodsArchiveList"
                    style="width: 100%; height: 100%;" idfield="id" allowresize="false" sizelist="[50,100,200,500]"
                    pagesize="200" multiselect="true">
                    <div property="columns">
                        <div type="indexcolumn" width="30">
                        </div>
                        <div field="bName" headeralign="center" align="center" width="60">
                            分店</div>
                        <div type="checkboxcolumn" field="Available" width="60" headeralign="center" onvaluechanged="availableChecked">
                            是否可用</div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        mini.parse();
        var grid = mini.get("datagrid1");
        var tree = mini.get("tree1");
        tree.on("nodeselect", function (e) {
            if (e.isLeaf) {
                var data = grid.getChanges();
                if (data.length > 0) {
                    saveData();
                }
                grid.url = "/Archives/GetRelationsBySupCode";
                grid.load({ id: e.node.Id });
            } else {
                grid.setData([]);
                grid.setTotalCount(0);
            }
        });
        function treesearch() {
            var value = mini.get("treekey").getValue();
            tree.load("/Archives/SearchAllSuppliersWithGoodsCount/" + value);
        }

        function showSearchWindow() {
            var win = mini.get("searchWindow");
            win.show();
        }
        function advSearch() {
            var frm = new mini.Form("frmAdv");
            grid.load(frm.getData(true));
            var win = mini.get("searchWindow");
            win.hide();
        }
        function search() {
            grid.load({
                "key": mini.get("#Id").value,
                "IfExamine": mini.get("#ifexame").value
            });
        }
        function saveData() {
            var data = grid.getChanges();
            var json = mini.encode(data);

            grid.loading("保存中，请稍后......");

            for (var i = 0; i < data.length; i++) {
                $.ajax({
                    url: "/Archives/SetSupplierBranchRelationValue",
                    data: {
                        bcode: data[i].bCode,
                        supCode: data[i].SupCode,
                        value: data[i].Available
                    },
                    type: "post",
                    success: function (text) {

                    },
                    error: function (jqXHR, textStatus, errorThrown) {
                        alert(jqXHR.responseText);
                    }
                });
            }
            grid.reload();

        }
        function selectAll() {
            $("input[type='checkbox']").each(function () {
                $(this).click();
            })
        }
    </script>
</body>
</html>
